package trungnt.wipeoff.model;

import trungnt.wipeoff.Cs;
import trungnt.wipeoff.PlayState;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class NumberActor extends Actor {

	private PlayState _playState = null;

	private Texture texture = null;
	private Sprite sprite = null;

	private int value = 0;
	private int rowIndex = 0;
	private int colIndex = 0;

	private boolean removed = false;
	private boolean justChangedTo9 = false;

	public NumberActor(PlayState playState, int value) {
		this._playState = playState;
		
		this.setTexture(value);
		
		this.setSize(Cs.CELL_SIZE.x, Cs.CELL_SIZE.y);
		this.setOrigin(Cs.CELL_SIZE.x / 2, Cs.CELL_SIZE.y / 2);
		
	}
	
	public void setTexture(int value){
		this.value = value;
		
		this.texture = this._playState.getGame().getAssetManager().get(Cs.FILE_NAME[this.value]);
		this.sprite = new Sprite(this.texture);
		
		this.sprite.setSize(Cs.CELL_SIZE.x, Cs.CELL_SIZE.y);
		
		if(value == 9)
		{
			this.justChangedTo9 = true;
		}
	}

	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		final Color c = getColor();
		batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);
		batch.draw(this.sprite, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
		
		this.justChangedTo9 = false;
	}

	public int getValue() {
		return this.value;
	}

	public int getColIndex() {
		return this.colIndex;
	}

	public int getRowIndex() {
		return this.rowIndex;
	}

	public void setIndex(int colIndex, int rowIndex) {
		this.colIndex = colIndex;
		this.rowIndex = rowIndex;
	}

	public void setRemoved(boolean removed) {
		this.removed = removed;
	}

	public boolean getRemoved() {
		return this.removed;
	}
	
	public boolean getJustChangedTo9() {
		return this.justChangedTo9;
	}
}
